Instrumentation is the process of using code to integrate monitoring and logging tools into your application. This allows you to track the performance and behavior of your application, and to debug issues in production.
In nextjs we use instrumentation.js(or .ts) file to integrate observability tools into our application and perform setup tasks the moment your server starts up. To use it, place the file in the root of your application or inside a src folder if using one.
register (optional): The file exports a register function that is called once when a new Next.js server instance is initiated. register can be an async function.
onRequestError (optional): You can optionally export an onRequestError function to track server errors to any custom observability provider. The function accepts three parameters: error, request, and context.